package test4;
//字符串拆分
public class TeseDemo4 {

    public static void main(String[] args) {
        String str="java 12&21#hello";
        String[] strings=str.split(" |&|#");
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main3(String[] args) {
        String str="192.168.1.1";
        String[] strings=str.split("\\.",2);// limit 表示分为几组，不一定是均匀分割
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main2(String[] args) {
        String str="192.168.1.1";
        String[] strings=str.split("\\.");// .需要加上转义字符
        for (String s:strings) {
            System.out.println(s);
        }
    }

    public static void main1(String[] args) {
        String str="name=zhangsan&age=19";
        String[] strings=str.split("&");
        for (String s:strings) {
            //System.out.println(s);//name=zhangsan   age=19
            String[] ss=s.split("=");
            for (String tmp:ss) {
                System.out.println(tmp);//name zhangsan age  19
            }
        }
    }
}
